/**
 * jQuery Footer Caption. This Plugin add a footer caption on an image
 * or DIV box and insert title or alt attribute like text.
 *
 * @option		height		Caption height (default 32px)
 * @option		alpha		Caption alpha opacity (default 0.7)
 * @option		bgcolor		Caption background color (default #000)
 * @option		color		Caption font color (default #fff)
 * @option		font		Caption font family name (default Verdana)
 * @option		fontSize	Caption font size (default 10px)
 * @option		text		Custom text. If setting title and alt are ignored (default '')
 *
 * @bugs
 *
 * Due the div wrapper TAG inline like IMG are displayed in block
 *
 * @usage
 *
 *	$('img').footerCaption();
 *
 * 	or
 *
 *	$('img.caption').footerCaption( { color: '#0096ff', text: 'Hello World!' } );
 *
 *
 * "Footer Caption" is released under version 3.0 of the Creative Commons 
 * Attribution-Noncommercial-Share Alike license. This means that it is 
 * absolutely free for personal, noncommercial use provided that you 1)
 * make attribution to the author and 2) release any derivative work under
 * the same or a similar license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * If you wish to use "Footer Caption" for commercial purposes, licensing information
 * can be found at http://www.undolog.com
 *
 * @author		Giovambattista Fazioli <g.fazioli@undolog.com>
 * @web			http://www.undolog.com
 * @version		1.0.0
 *
 * @changelog
 *	+ 1.0.0		First release
 *
 *
 */
(function($){
	$.fn.extend( {
		footerCaption: function(options){
			/**
			 * Set default options
			 */
			var defaults = {
								height			: '32px',
								alpha			: '0.7',
								bgcolor			: '#000',
								color			: '#fff',
								font			: 'Verdana',
								fontSize		: '10px',
								textAlign		: 'left',
								text			: ''
						   };
			var options = $.extend(defaults, options);
			return this.each(function(){
				var __e = $(this);

				var w 		= __e.width();
				var title	= ( __e.attr('title') == undefined)?'':__e.attr('title');
				var alt		= ( __e.attr('alt') == undefined)?'':__e.attr('alt');
				var text 	= ( options.text == '')?( (title == '')?( (alt == '')?'':alt ):title ):options.text;
				
				/**
				 * If "title" and "alt" attribues are not settings, do nothing
				 */
				if( text != '' )
					__e.
						wrap(document.createElement("div")).
						parent().
						css( 'width', w ).
						append( '<div><p></p></div>' ).
						children('div:last').
						css( {  width 				: w, 
								height 				: options.height,
								color 				: options.color, 
								lineHeight 			: options.height, 
								fontFamily	 		: options.font, 
								fontSize 			: options.fontSize, 
								backgroundColor 	: options.bgcolor,
								position			: 'relative',
								marginTop 			: '-'+options.height, 
								opacity 			: options.alpha, 
								display 			: 'none' 
							} ).
						children('p').
						css( { 
								paddingLeft			: '12px', 
								margin				: '0',
								textAlign			: options.textAlign 
							 } ).
						html( text ).
						parent().slideDown('slow');
			});
		}
	});
})(jQuery);